﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RootBaseFramework.Policy.RootEntiyBase
{
  public class IsParentValid:ISpecification<IBloodLine>
     {

      IBloodLine _thisLine;
      public IsParentValid(IBloodLine thisLine)
      {
          _thisLine = thisLine;
      }


       public bool IsSatisfiedBy(IBloodLine candidateParent)
       {
           bool isValid = true;


         string  pLine = candidateParent.BloodLine;
          pLine= pLine.Trim(candidateParent.Delimeter);

          string[] pLines = pLine.Split(candidateParent.Delimeter);

          string cLine = _thisLine.BloodLine;
         cLine= cLine.Trim(_thisLine.Delimeter);
          string[] cLines = cLine.Split(_thisLine.Delimeter);

           //1 child cannot be its own parent

          string childIdenty = _thisLine.Delimeter + cLines.Last() + _thisLine.Delimeter;
          string parentIdentity = pLines.Last();

          if (pLines.Contains(childIdenty))
              isValid = false;




          return isValid;

       }
     }
}
